package com.android.porttallymansystem.logic.service

import android.app.AlarmManager
import android.app.PendingIntent
import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.widget.Toast
import com.amap.api.location.AMapLocationClient
import com.amap.api.location.AMapLocationClientOption
import com.amap.api.maps.model.LatLng
import com.android.porttallymansystem.logic.Repository

class LocationService: Service() {

    private lateinit var mLocationClient: AMapLocationClient

    override fun onCreate() {
        super.onCreate()
        mLocationClient = AMapLocationClient(applicationContext)

        initLocationOption()

        mLocationClient.setLocationListener { location ->
            val latLng = LatLng(location.latitude, location.longitude)
            Repository.addLatLng(latLng)
        }
        mLocationClient.startLocation()
    }

    private fun initLocationOption() {
        val mLocationOption = AMapLocationClientOption()
        // 使用连续定位
        mLocationOption.isOnceLocation = false
        // 每10秒定位一次
        mLocationOption.interval = 10 * 1000
        mLocationClient.setLocationOption(mLocationOption)
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        return super.onStartCommand(intent, flags, startId)
    }

    override fun onDestroy() {
        super.onDestroy()
    }

    override fun onBind(intent: Intent?): IBinder? {
        TODO("Not yet implemented")
    }
}